import React, { forwardRef, useRef } from 'react';
import { Modal } from 'antd';
import DataForm from './DataForm';
import { useModel } from '@umijs/max';

const ModalForm: React.FC = forwardRef((props,ref) => {
  //数据模型
  const roleModel = useModel('admin.rule_category', (model) => ({
    data: model.data,
  }));
  // 表单
  const formRef = useRef();
  return (
    <Modal
      title={roleModel.data.id ? '编辑' : '新建'}
      mask={true}
      maskClosable={false}
      destroyOnClose={true}
      onCancel={() => {
        props.onCancel();
      }}
      visible={props.modalVisible}
      footer={false}
    >
      <DataForm
        ref={formRef}
        onSubmit={async (res) => {
          props.onSubmit(res);
        }}
      />
    </Modal>
  );
});

export default ModalForm;
